package com.csun.cmny.provider.controller.hualong;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.dto.HuaLongMedicRecordQueryDto;
import com.csun.cmny.provider.model.domain.OmcHuaLongMedicRecord;
import com.csun.cmny.provider.model.dto.hualong.HuaLongRosterDto;
import com.csun.cmny.provider.model.dto.hualong.HuaLongRosterQueryDto;
import com.csun.cmny.provider.model.vo.hualong.HuaLongRosterVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcHuaLongMedicRecordService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020-11-09 10:34
 * @Description:
 */
@RestController
@RequestMapping("/hualong/medicRecord")
public class OmcHuaLongMedicRecordController extends BaseController {

    @Resource
    private OmcHuaLongMedicRecordService omcHuaLongMedicRecordService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;


    /**
     * 护工保存记录
     */
    @PostMapping(value = "/save")
    public Wrapper save(@RequestBody OmcHuaLongMedicRecord omcHuaLongMedicRecord) {

        // TODO 是否为主管

        Integer result = omcHuaLongMedicRecordService.save(omcHuaLongMedicRecord, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                result);
    }

    /**
     * 查询主管排班列表
     */
    @PostMapping(value = "/queryListWithPage")
    public Wrapper queryListWithPage(@RequestBody HuaLongMedicRecordQueryDto huaLongMedicRecordQueryDto) {

        huaLongMedicRecordQueryDto.setGroupId(getLoginAuthDto().getGroupId());

        List<OmcHuaLongMedicRecord> huaLongMedicRecordList = omcHuaLongMedicRecordService.queryListWithPage(huaLongMedicRecordQueryDto);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                new PageInfo<>(huaLongMedicRecordList));
    }

    /**
     * 护工保存记录
     */
    @PostMapping(value = "/queryById/{id}")
    public Wrapper queryById(@PathVariable Long id) {

        OmcHuaLongMedicRecord omcHuaLongMedicRecord = omcHuaLongMedicRecordService.selectByKey(id);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                omcHuaLongMedicRecord);
    }

    /**
     * 删除记录Id
     */
    @PostMapping(value = "/deleteById/{id}")
    public Wrapper deleteById(@PathVariable Long id) {

        Integer result = omcHuaLongMedicRecordService.deleteByKey(id);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,
                cmnyMessageSource.getMessage("operation.success", null),
                result);
    }

}
